import json

import pymysql
from flask import Flask, request

app = Flask(__name__)

conn = pymysql.connect(
    host='127.0.0.1',
    port=3306,
    user='root',
    password='123456',
    database='mumushouji',
    charset='utf8',
    autocommit=True
    # cursorclass=pymysql.cursors.DictCursor
)

cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)


@app.route('/', methods=['post'])
def update_user_info():
    request_data = request.data
    request_data = json.loads(request_data)
    print(request_data)
    username = request_data.get('username')
    nickname = request_data.get('nickname')
    print(username)
    print(nickname)
    sql = 'update user set nickname = %(nickname)s where username=%(username)s'
    params = {
        'nickname': nickname,
        'username': username
    }
    cursor.execute(sql, params)
    # conn.commit()
    return '修改用户信息成功'


if __name__ == '__main__':
    app.run(debug=True)
